class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None


class Solution:
    def addTwoNumbers(self, l1, l2):

        low_num = 0
        val = l1.val + l2.val + low_num
        if val < 10:
            result_list = ListNode(val)
            low_num = 0
        else:
            result_list = ListNode(val - 10)
            low_num = 1

        tmp1 = l1.next
        tmp2 = l2.next
        tmp3 = result_list
        while tmp1 != None or tmp2 != None:
            if tmp1 != None and tmp2 != None:
                val = tmp1.val + tmp2.val + low_num
   
                tmp1 = tmp1.next
                tmp2 = tmp2.next
            elif tmp1 != None:
                val = tmp1.val + low_num
                tmp1 = tmp1.next
            elif tmp2 != None:
                val = tmp2.val + low_num
                tmp2= tmp2.next
             
            if val < 10:
                tmp_node = ListNode(val)
                low_num = 0
            else:
                tmp_node = ListNode(val - 10)
                low_num = 1
                    
                    
            tmp3.next = tmp_node
            tmp3 = tmp3.next

        if low_num != 0:
            tmp3.next = ListNode(low_num)

        return  result_list
        pass
